package com.pdg.android.rockscissorspaper;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class StatisticsActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.statistics);
        refreshStatistics();
    }
	private void refreshStatistics() {
		showStat(R.id.matches_played,R.string.matches_played,Settings.getNumberOfMatches(this));
		showStat(R.id.matches_won,R.string.matches_won,Settings.getNumberOfMatchWins(this));
		showStat(R.id.matches_lost,R.string.matches_lost,Settings.getNumberOfMatchLosses(this));

		showStat(R.id.rocks_used,R.string.rocks_used,Settings.getNumberOfRockPlays(this));
		showStat(R.id.rock_wins,R.string.rock_wins,Settings.getNumberOfRockWins(this));
		showStat(R.id.rock_losses,R.string.rock_losses,Settings.getNumberOfRockLosses(this));
		showStat(R.id.rock_ties,R.string.rock_ties,Settings.getNumberOfRockTies(this));

		showStat(R.id.scissors_used,R.string.scissors_used,Settings.getNumberOfScissorsPlays(this));
		showStat(R.id.scissors_wins,R.string.scissors_wins,Settings.getNumberOfScissorsWins(this));
		showStat(R.id.scissors_losses,R.string.scissors_losses,Settings.getNumberOfScissorsLosses(this));
		showStat(R.id.scissors_ties,R.string.scissors_ties,Settings.getNumberOfScissorsTies(this));

		showStat(R.id.papers_used,R.string.papers_used,Settings.getNumberOfPaperPlays(this));
		showStat(R.id.paper_wins,R.string.paper_wins,Settings.getNumberOfPaperWins(this));
		showStat(R.id.paper_losses,R.string.paper_losses,Settings.getNumberOfPaperLosses(this));
		showStat(R.id.paper_ties,R.string.paper_ties,Settings.getNumberOfPaperTies(this));

	}
	private void showStat(int theControlId, int theStringId,
			int theNumber) {
		TextView tv = (TextView)findViewById(theControlId);
		String theFormat = getString(theStringId);
		tv.setText(String.format(theFormat,theNumber));
	}
	public void backButtonPressed(View theView){
        Intent myIntent = new Intent(theView.getContext(), MainMenuActivity.class);
        startActivityForResult(myIntent, 0);
	}
	public void clearStatisticsButtonPressed(View theView){
		Settings.resetStatistics(this);
		refreshStatistics();
	}
}
